package com.alibaba.travel.article.controller;

import java.util.Arrays;
import java.util.Map;

import com.alibaba.travel.article.entity.UserArticleHistoryEntity;
import com.alibaba.travel.article.service.UserArticleHistoryService;
import com.alibaba.travel.common.utils.PageUtils;
import com.alibaba.travel.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;




/**
 * 用户文章浏览历史表
 *
 * @author wherezy
 * @email wherezy@tom.com
 * @date 2023-02-23 15:08:53
 */
@Api(tags = {"用户文章浏览历史表UserArticleHistoryController"})
@RestController
@RequestMapping("article/userarticlehistory")
public class UserArticleHistoryController {
    @Autowired
    private UserArticleHistoryService userArticleHistoryService;

    /**
     * 通过用户id获取历史浏览文章点赞数量
     */
    @ApiOperation(value="通过用户id获取历史浏览文章点赞数量", notes="用户id")
    @PostMapping("/count")
    public R count(@RequestParam Long userId){
        Long count = userArticleHistoryService.getLikesByArticleId(userId);

        return R.ok().put("count", count);
    }

    /**
     * 列表
     */
    @ApiOperation(value="分页获取信息", notes="k-v map形式封装分页参数")
    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = userArticleHistoryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value="获取信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		UserArticleHistoryEntity userArticleHistory = userArticleHistoryService.getById(id);

        return R.ok().put("userArticleHistory", userArticleHistory);
    }

    /**
     * 保存
     */
    @ApiOperation(value="保存")
    @PostMapping("/save")
    public R save(@RequestBody UserArticleHistoryEntity userArticleHistory){
		userArticleHistoryService.save(userArticleHistory);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改")
    @PostMapping("/update")
    public R update(@RequestBody UserArticleHistoryEntity userArticleHistory){
		userArticleHistoryService.updateById(userArticleHistory);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value="删除")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		userArticleHistoryService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
